package world;

import com.jme.bounding.BoundingSphere;
import com.jme.light.PointLight;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.system.DisplaySystem;
//TODO Make the star rotate
//FIXME Light does not work
public class WorldStar {
	
	/**
	 * Creates a star
	 * @return star
	 */
	private Sphere createStar(){
		//TODO Instead of using a color I'd like to use a texture of an old red star.
		Sphere star = new Sphere("The star",10,10,10f);
		star.setDefaultColor(ColorRGBA.red);
		star.setModelBound(new BoundingSphere());
		star.updateModelBound();
		return star;
	}
	
	/**
	 * Creates a light 
	 * @return light 
	 */
	private LightState createLight(){
		//Create a light state from the renderer 
		LightState lightState= DisplaySystem.getDisplaySystem().getRenderer().createLightState();
		PointLight starLight = new PointLight();
		starLight.setAmbient(ColorRGBA.red);
		starLight.setEnabled(true);
		lightState.attach(starLight);
		lightState.setEnabled(true);
		return lightState;
	}
	
	public Node getStar(){
		MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState(); 
		ms.setEmissive(ColorRGBA.red);
		//Make a node to package the star and the light
		Node star = new Node();
		Sphere sphereStar = createStar();
		star.attachChild(sphereStar);
		//Set the render state of the star to use the light
		star.setRenderState(this.createLight());
		star.setRenderState(ms);
		return star;
	}
}
